package butines.kraz.state;

import butines.kraz.entity.AbstractState;
import butines.kraz.entity.Unit;


public class UnitStayState extends AbstractState<Unit> {

	private static final UnitStayState instance = new UnitStayState();

	public static UnitStayState getInstance() {
		return instance;
	}

	@Override
	public void enter(Unit owner) {
		owner.setSpeed(0);
		owner.getSteering().getSeparation().on();
	}
	
	@Override
	public void leave(Unit owner) {
		owner.getSteering().getSeparation().off();
	}

	@Override
	public void execute(Unit owner) {
		
		if (owner.getVelocity().lengthSq() > .01f) {
			
			if (owner.getSprite().isAnimation("walk")) {
				owner.getSprite().resume();
			} else {
				owner.getSprite().play("walk");
			}
			
		} else {
			
			if (!owner.getSprite().isAnimation("stay")) {
				owner.getSprite().play("stay");
			}
			
		}
	}


}
